<ui:composition xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:fn="http://java.sun.com/jsp/jstl/functions"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets" template="/home.xhtml">
	<ui:define name="corpo">
		<h:form prependId="false">
			<p:panel header="Administrar Clínicas" style="background: #dbfbda;font-size:15px;min-height:700px;margin-top:10px;float:left;width:99%">
				<h:panelGroup style="float: left;width:250px;" layout="block">
					<ui:include src="menu.xhtml" />
				</h:panelGroup>
				<h:panelGroup layout="block" style="float:left">
				    	<p:dataTable var="clinica" value="#{manterAdministradorBean.administradorForm.clinicas}" paginator="true" id="table_clinica" rows="15"  
				                 paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}" 
				                 paginatorPosition="bottom" style="width:700px">  
					  
				            <f:facet name="header">  
				                <h:outputText value="Clínicas Cadastradas" />
				            </f:facet>  
					        <p:column>  
					            <f:facet name="header">  
					                <h:outputText value="Clínica" />  
					            </f:facet>  
					            <h:outputText value="#{clinica.clinica}" />  
					        </p:column>  
´
					        <p:column>  
					            <f:facet name="header">  
					                <h:outputText value="Email" />  
					            </f:facet>  
					            <h:outputText value="#{clinica.email}" />  
					        </p:column>  
					  
					        <p:column style="text-align: center">  
					            <f:facet name="header">  
					                <h:outputText value="Excluir" />  
					            </f:facet>  
					            <p:commandButton image="ui-icon ui-icon-trash" oncomplete="excluir.show()">
					            	<f:setPropertyActionListener target="#{manterClinicaBean.clinica}" value="#{clinica}" />
					            </p:commandButton>
					        </p:column>  
	
					        <p:column style="text-align: center">  
					            <f:facet name="header">  
					                <h:outputText value="Editar" />  
					            </f:facet>  
					            <p:commandButton image="ui-icon ui-icon-transferthick-e-w" oncomplete="editar.show()" update="pnl_edit">
					            	<f:setPropertyActionListener target="#{manterClinicaBean.clinica}" value="#{clinica}" />					            	
					            </p:commandButton>
					        </p:column>  
					  
					  		<f:facet name="footer">
				                <p:commandButton value="Cadastrar" image="ui-icon ui-icon-circle-plus" style="position: relative; right: 290px;" oncomplete="cadastrar.show()" action="#{manterClinicaBean.limparCampo}" update="pnl_cadastro" />
				            </f:facet>
					    </p:dataTable>
			    </h:panelGroup>
			 
			</p:panel>
			
		</h:form>
		
		<ui:include src="modal_excluir_admin.xhtml">
			<ui:param name="bean" value="#{manterClinicaBean}" />
			<ui:param name="metodo" value="excluir" />
			<ui:param name="idTabela" value="table_clinica" />
		</ui:include>
		
		<p:dialog header="Editar" widgetVar="editar" resizable="false" modal="true" width="500" showEffect="clip" hideEffect="fold">
			<h:form prependId="false">
				<h:panelGrid columns="2" cellspacing="0" cellpadding="2" id="pnl_edit" style="margin-top:10px">
				
					<h:panelGroup>
						<font class="campoObrigatorio">*</font>
						<h:outputLabel value="#{msg['display.label.clinica.nome']}" style="font-weight:bold" for="nome" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>						
					<p:inputText value="#{manterClinicaBean.clinica.clinica}" size="50" maxlength="100" label="nome" required="true" id="nome" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:message for="nome" id="msgNome" styleClass="msg_erro_required"/>
					
					<h:panelGroup>
						<font class="campoObrigatorio">*</font>
						<h:outputLabel value="#{msg['display.label.clinica.cnpj']}" style="font-weight:bold" for="cnpj" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>					
					<p:inputMask value="#{manterClinicaBean.clinica.cnpj}" size="20" mask="99.999.999/9999-99" label="cnpj" required="true" id="cnpj" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro">
						<f:converter converterId="com.automed.cnpjConverter"/>
						<f:validator validatorId="com.automed.cnpjValidator"/>
					</p:inputMask>					
					<h:outputText />
					<h:message for="cnpj" id="msgCnpj" styleClass="msg_erro_required"/>

					<h:panelGroup>
						<font class="campoObrigatorio">*</font>
						<h:outputLabel value="#{msg['display.label.clinica.email']}" style="font-weight:bold" for="email" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>					
					<p:inputText value="#{manterClinicaBean.clinica.email}" size="35" maxlength="100" label="email" required="true" id="email" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro">
						<f:validator validatorId="com.automed.emailValidator"/>
					</p:inputText>					
					<h:outputText />
					<h:message for="email" id="msgEmail" styleClass="msg_erro_required"/>
					
					<h:panelGroup>
						<font class="campoObrigatorio">*</font>
						<h:outputLabel value="#{msg['display.label.clinica.cep']}" for="cep" style="font-weight:bold" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>					
					<p:inputMask value="#{manterClinicaBean.clinica.endereco.cep}" mask="99999-999" size="10" maxlength="8" required="true" label="cep" id="cep" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:message for="cep" id="msgCEP" styleClass="msg_erro_required"/>
					
					<h:panelGroup>
						<font class="campoObrigatorio">*</font>
						<h:outputLabel value="#{msg['display.label.clinica.bairro']}" style="font-weight:bold" for="bairro" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>					
					<p:inputText value="#{manterClinicaBean.clinica.endereco.bairro}" required="true" size="30" maxlength="100" label="bairro" id="bairro" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:message for="bairro" id="msgBairro" styleClass="msg_erro_required"/>
					
					<h:panelGroup>
						<font class="campoObrigatorio">*</font>
						<h:outputLabel value="#{msg['display.label.clinica.logradouro']}" style="font-weight:bold" for="logradouro" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>					
					<p:inputText value="#{manterClinicaBean.clinica.endereco.endereco}" required="true" size="50" maxlength="100" label="logradouro" id="logradouro" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:message for="logradouro" id="msgLogradouro" styleClass="msg_erro_required"/>

					<h:panelGroup>
						<font class="campoObrigatorio">*</font>
						<h:outputLabel value="#{msg['display.label.clinica.numero']}" style="font-weight:bold" for="numero" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>					
					<p:inputMask value="#{manterClinicaBean.clinica.endereco.numero}" required="true" mask="?999999" size="6" label="numero" id="numero" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:message for="numero" id="msgNumero" styleClass="msg_erro_required" />
					
					<h:panelGroup>
						<h:outputLabel value="#{msg['display.label.clinica.complemento']}" for="complemento" style="font-weight:bold" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>					
					<p:inputText value="#{manterClinicaBean.clinica.endereco.complemento}" required="false" size="6" maxlength="50" label="complemento" id="complemento" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:message for="complemento" id="msgComplemento" styleClass="msg_erro_required"/>

					<h:panelGroup>
						<font class="campoObrigatorio">*</font>
						<h:outputLabel value="#{msg['display.label.clinica.cidade']}" for="cidade" style="font-weight:bold" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>									
					<h:selectOneMenu value="#{manterClinicaBean.clinica.endereco.cidade}" id="cidade" style="font-size:12px">
						<f:selectItem itemLabel="" />	
						<f:selectItems value="#{manterClinicaBean.clinicaForm.cidades}" var="entity" itemLabel="#{entity.cidade}" itemValue="#{entity}" />
					</h:selectOneMenu>
					<h:outputText />
					<h:message for="cidade" id="msgCidade" styleClass="msg_erro_required"/>

					<ui:repeat var="entity" value="#{manterClinicaBean.clinica.telefones}">
					
						<h:outputLabel style="font-weight:bold" value="#{entity.tipoTelefone.tipo eq 'Comercial' ? 'Telefone 1: ' : (entity.tipoTelefone.tipo eq 'Residencial' ? 'Telefone 2: ' : '')}" for="tel1" styleClass="fmt_label_form_cadastro" />
						<p:inplace emptyLabel="Adicionar">
							<p:inputMask value="#{entity.telefone}" mask="(99)9999-9999" required="true" label="#entity.tipoTelefone.tipo eq 'Comercial' ? 'Telefone 1' : (entity.tipoTelefone.tipo eq 'Residencial' ? 'Telefone 2' : '')}" id="tel1" size="15" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
						</p:inplace>
						<h:outputText />
						<h:message for="tel1" id="msgTEL1" styleClass="msg_erro_required"/>
						
					</ui:repeat>
					
				</h:panelGrid>
				
				<h:panelGroup style="padding-top: 20px;padding-bottom:10px;text-align:center" layout="block">
					<p:commandButton value="#{msg['display.view.adm.salvar']}" action="#{manterClinicaBean.editar}" oncomplete="validaEdicao();" update="pnl_edit, table_clinica, func_javascript"/>
					<p:commandButton value="#{msg['display.view.adm.cancelar']}" oncomplete="editar.hide()"/>
				</h:panelGroup>
			</h:form>
	    </p:dialog>
	    
	    <p:dialog header="Cadastrar" widgetVar="cadastrar" resizable="false" modal="true" width="500" showEffect="clip" hideEffect="fold">
			<h:form prependId="false">
				<h:panelGrid columns="4" cellspacing="0" cellpadding="2" id="pnl_cadastro">
				
					<h:panelGroup>
						<font class="campoObrigatorio">*</font>
						<h:outputLabel value="#{msg['display.label.clinica.nome']}" style="font-weight:bold" for="nomeCad" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>					
					<p:inputText value="#{manterClinicaBean.clinica.clinica}" size="50" maxlength="100" label="nome" required="true" id="nomeCad" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:outputText />
					
					<h:outputText />
					<h:message for="nomeCad" id="msgNomeCad" styleClass="msg_erro_required"/>
					<h:outputText />
					<h:outputText />

					<h:panelGroup>
						<font class="campoObrigatorio">*</font>
						<h:outputLabel value="#{msg['display.label.clinica.cnpj']}" style="font-weight:bold" for="cnpjCad" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>					
					<p:inputMask value="#{manterClinicaBean.clinica.cnpj}" size="20" mask="99.999.999/9999-99" label="cnpj" required="true" id="cnpjCad" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro">
						<f:converter converterId="com.automed.cnpjConverter"/>
						<f:validator validatorId="com.automed.cnpjValidator"/>
					</p:inputMask>
					<h:outputText />
					<h:outputText />
					
					<h:outputText />
					<h:message for="cnpjCad" id="msgCnpjCad" styleClass="msg_erro_required"/>
					<h:outputText />
					<h:outputText />
					
					<h:panelGroup>
						<font class="campoObrigatorio">*</font>
						<h:outputLabel value="#{msg['display.label.clinica.email']}" style="font-weight:bold" for="emailCad" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>					
					<p:inputText value="#{manterClinicaBean.clinica.email}" size="35" maxlength="100" label="email" required="true" id="emailCad" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro">
						<f:validator validatorId="com.automed.emailValidator"/>
					</p:inputText>
					<h:outputText />
					<h:outputText />
					
					<h:outputText />
					<h:message for="emailCad" id="msgEmailCad" styleClass="msg_erro_required"/>
					<h:outputText />
					<h:outputText />
					
					<h:panelGroup>
						<font class="campoObrigatorio">*</font>
						<h:outputLabel value="#{msg['display.label.clinica.tel1']}" style="font-weight:bold" for="tel1Cad" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>					
					<p:inputMask value="#{manterClinicaBean.comercial.telefone}" size="15" mask="(99)9999-9999" label="telefone 1" required="true" id="tel1Cad" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:outputText />
					
					<h:outputText />
					<h:message for="tel1Cad" id="msgTel1Cad" styleClass="msg_erro_required"/>
					<h:outputText />
					<h:outputText />

					<h:panelGroup>
						<font class="campoObrigatorio">*</font>
						<h:outputLabel value="#{msg['display.label.clinica.tel2']}" style="font-weight:bold" for="tel2Cad" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>					
					<p:inputMask value="#{manterClinicaBean.residencial.telefone}" size="15" mask="(99)9999-9999" label="telefone 2" required="true" id="tel2Cad" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:outputText />
					
					<h:outputText />
					<h:message for="tel2Cad" id="msgTel2Cad" styleClass="msg_erro_required"/>
					<h:outputText />
					<h:outputText />
					
					<h:panelGroup>
						<font class="campoObrigatorio">*</font>
						<h:outputLabel value="#{msg['display.label.clinica.cep']}" style="font-weight:bold" for="cepCad" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>						
					<p:inputMask value="#{manterClinicaBean.clinica.endereco.cep}" mask="99999-999" size="10" maxlength="8" required="true" label="cep" id="cepCad" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:outputText />
					
					<h:outputText />
					<h:message for="cepCad" id="msgCEPCad" styleClass="msg_erro_required"/>
					<h:outputText />
					<h:outputText />
					
					<h:panelGroup>
						<font class="campoObrigatorio">*</font>
						<h:outputLabel value="#{msg['display.label.clinica.bairro']}" style="font-weight:bold" for="bairroCad" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>					
					<p:inputText value="#{manterClinicaBean.clinica.endereco.bairro}" required="true" size="30" maxlength="100" label="bairro" id="bairroCad" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:outputText />
					
					<h:outputText />
					<h:message for="bairroCad" id="msgBairroCad" styleClass="msg_erro_required"/>
					<h:outputText />
					<h:outputText />
					
					<h:panelGroup>
						<font class="campoObrigatorio">*</font>
						<h:outputLabel value="#{msg['display.label.clinica.logradouro']}" style="font-weight:bold" for="logradouroCad" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>					
					<p:inputText value="#{manterClinicaBean.clinica.endereco.endereco}" required="true" size="50" maxlength="100" label="logradouro" id="logradouroCad" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:outputText />
					
					<h:outputText />
					<h:message for="logradouroCad" id="msgLogradouroCad" styleClass="msg_erro_required"/>
					<h:outputText />
					<h:outputText />
					
					<h:panelGroup>
						<font class="campoObrigatorio">*</font>
						<h:outputLabel value="#{msg['display.label.clinica.numero']}" style="font-weight:bold" for="numeroCad" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>					
					<p:inputMask value="#{manterClinicaBean.clinica.endereco.numero}" required="true" mask="?999999" size="6" label="numero" id="numeroCad" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:outputText />
					
					<h:outputText />
					<h:message for="numeroCad" id="msgNumeroCad" styleClass="msg_erro_required" />
					<h:outputText />
					<h:outputText />

					<h:panelGroup>
						<h:outputLabel value="#{msg['display.label.clinica.complemento']}" style="font-weight:bold" for="complementoCad" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>					
					<p:inputText value="#{manterClinicaBean.clinica.endereco.complemento}" required="false" size="6" maxlength="50" label="complemento" id="complementoCad" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:outputText />
					
					<h:outputText />
					<h:message for="complementoCad" id="msgComplementoCad" styleClass="msg_erro_required"/>
					<h:outputText />
					<h:outputText />

					<h:panelGroup>
						<font class="campoObrigatorio">*</font>
						<h:outputLabel value="#{msg['display.label.clinica.cidade']}" style="font-weight:bold" for="cidadeCad" styleClass="fmt_label_form_cadastro" />
					</h:panelGroup>					
					<h:selectOneMenu value="#{manterClinicaBean.clinica.endereco.cidade}" required="true" label="Cidade" id="cidadeCad" style="font-size:12px">
						<f:selectItem itemLabel=""/>
						<f:selectItems value="#{manterClinicaBean.clinicaForm.cidades}" var="entity" itemLabel="#{entity.cidade}" itemValue="#{entity}" />
					</h:selectOneMenu>
					<h:outputText />
					<h:outputText />
					
					<h:outputText />
					<h:message for="cidadeCad" id="msgCidadeCad" styleClass="msg_erro_required"/>
					<h:outputText />
					<h:outputText />
				
				</h:panelGrid>
				<h:panelGroup style="padding-top: 20px;padding-bottom:10px;text-align:center" layout="block">
					<p:commandButton value="#{msg['display.view.adm.salvar']}" action="#{manterClinicaBean.cadastrar}" oncomplete="validaCadastro();" update="pnl_cadastro, table_clinica, func_javascript"/>
					<p:commandButton value="#{msg['display.view.adm.cancelar']}" onclick="cadastrar.hide()"/>
				</h:panelGroup>
				
				<p:outputPanel id="func_javascript">
					<script type="text/javascript">
	
						function validaCadastro(){
							if(#{!empty requestScope.cadastrado}){
								cadastrar.hide();
							}
						}
										
						function validaEdicao(){
							if(#{!empty requestScope.editado}){
								editar.hide();
							}
						}						
								
					</script>
				</p:outputPanel>
				
			</h:form>
	    </p:dialog>
		
	</ui:define>
</ui:composition>